package cn.stylefeng.guns.modular.api.controller;

import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.api.entity.TaskRecord;
import cn.stylefeng.guns.modular.api.model.params.TaskRecordParam;
import cn.stylefeng.guns.modular.api.model.result.TaskRecordResult;
import cn.stylefeng.guns.modular.api.service.TaskRecordService;
import cn.stylefeng.roses.core.base.controller.BaseController;
import cn.stylefeng.roses.core.reqres.response.ResponseData;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;


/**
 * 任务记录控制器
 *
 * @author samwuu
 * @Date 2019-10-10 22:59:49
 */
@Controller
@RequestMapping("/api/taskRecord")
public class TaskRecordController extends BaseController {

    private String PREFIX = "/taskRecord";

    @Autowired
    private TaskRecordService taskRecordService;

    /**
     * 跳转到主页面
     *
     * @author samwuu
     * @Date 2019-10-10
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "/taskRecord.html";
    }

    /**
     * 新增页面
     *
     * @author samwuu
     * @Date 2019-10-10
     */
    @RequestMapping("/add")
    public String add() {
        return PREFIX + "/taskRecord_add.html";
    }

    /**
     * 编辑页面
     *
     * @author samwuu
     * @Date 2019-10-10
     */
    @RequestMapping("/edit")
    public String edit() {
        return PREFIX + "/taskRecord_edit.html";
    }

    /**
     * 新增接口
     *
     * @author samwuu
     * @Date 2019-10-10
     */
    @RequestMapping("/addItem")
    @ResponseBody
    public ResponseData addItem(TaskRecordParam taskRecordParam) {
        this.taskRecordService.add(taskRecordParam);
        return ResponseData.success();
    }

    /**
     * 更新接口
     *
     * @author samwuu
     * @Date 2019-10-10
     */
    @RequestMapping("/editItem")
    @ResponseBody
    @ApiOperation(value = "更新接口", notes = "更新", response = ResponseData.class)
    @ApiResponses({@ApiResponse(code = 200, message = "更新", response = ResponseData.class)})
    public ResponseData editItem(TaskRecordParam taskRecordParam) {
        this.taskRecordService.update(taskRecordParam);
        return ResponseData.success();
    }

    /**
     * 删除接口
     *
     * @author samwuu
     * @Date 2019-10-10
     */
    @RequestMapping("/delete")
    @ResponseBody

    public ResponseData delete(TaskRecordParam taskRecordParam) {
        this.taskRecordService.delete(taskRecordParam);
        return ResponseData.success();
    }

    /**
     * 查看详情接口
     *
     * @author samwuu
     * @Date 2019-10-10
     */
    @RequestMapping("/detail")
    @ResponseBody
    @ApiOperation(value = "详情接口", notes = "详情", response = TaskRecordResult.class)
    @ApiResponses({@ApiResponse(code = 200, message = "详情", response = TaskRecordResult.class)})
    public ResponseData detail(TaskRecordParam taskRecordParam) {
        TaskRecordResult detail = this.taskRecordService.findBySpec(taskRecordParam);
        return ResponseData.success(detail);
    }

    /**
     * 查询列表
     *
     * @author samwuu
     * @Date 2019-10-10
     */
    @ResponseBody
    @RequestMapping("/list")
    @ApiOperation(value = "列表接口", notes = "列表", response = TaskRecordResult.class)
    @ApiResponses({@ApiResponse(code = 200, message = "列表", response = TaskRecordResult.class)})
    public LayuiPageInfo list(TaskRecordParam taskRecordParam) {
        return this.taskRecordService.findPageBySpec(taskRecordParam);
    }

}


